package com.loadmore.baselibrary;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.loadmore.baselibrary.bean.Event;
import com.loadmore.baselibrary.util.Constants;
import com.loadmore.baselibrary.util.LogUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * @author sunleilei
 * @date 2017/5/14
 */

public class BaseActivity extends AppCompatActivity {

    public Context context;
    public Bundle bundle;
    public static String sign = null;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = this;
        bundle = getIntent().getBundleExtra(Constants.DATA);
        App.getApplication().addActivity(this);
        EventBus.getDefault().register(this);
        sign = getClass().getSimpleName();
        LogUtil.e(sign);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(Event event) {
        onEvent(event);
    }

    public void onEvent(Event event) {

    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        LogUtil.e("finalize");
    }

    @Override
    public void finish() {
        super.finish();
        App.getApplication().removeActivity();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
